package com.cdks.wuxiu.api.component.cdks.kmsg;

import cn.hutool.json.JSONUtil;

import com.cdks.wuxiu.api.model.dto.KmsgDataDTO;
import com.cdks.wuxiu.api.util.HttpUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.TreeMap;

import org.springframework.stereotype.Component;



@Slf4j
@Component
public class Auth {
    public static KmsgDataDTO getKmsgAuthData(long userId)
    {
        Map<String, Object> body  = new TreeMap<String, Object>();
        body.put("userId", userId);

        String ret  = HttpUtils.send_post_request("http://localhost:8183/kmsg/getUserToken.php", null, JSONUtil.toJsonStr(body));
        if (ret == null) {
            return null;
        }

        log.info("==== kmsg auth: " + ret);
        AuthResult result  = JSONUtil.toBean(ret, AuthResult.class);
        
        if ((result != null) && (result.getCode() == 0))
        {
            return result.getData();
        }

        return null;
    }
}
